package utils

import (
	"back/app/config"
	"os"
)

type CreateDir struct {
}

/**
 * 根据用户名创建目录结构
 */
func (c CreateDir) CreateDir(userName string) (err error) {
	key1 := [3]string{"origin", "dealt", "upload"}
	key2 := [3]string{"run", "walk", "shake"}
	key3 := [3]string{"amp", "phase", "abnormal"}
	filepath := ""

	i := 0
	j := 0
	k := 0

	for i = 0; i < 3; i++ {
		for j = 0; j < 3; j++ {
			for k = 0; k < 3; k++ {
				if i == 0 {
					if k == 2 {
						continue
					}
					//服务器上使用以下路径
					filepath = "./data/" + userName + "/" + key1[i] + "/" + key2[j] + "/" + key3[k]
					//本地运行使用以下代码
					//filepath = ".\\data\\" + userName + "\\" + key1[i] + "\\" + key2[j] + "\\" + key3[k]
				} else if i == 1 {
					//服务器上使用以下路径
					filepath = "./data/" + userName + "/" + key1[i] + "/" + key2[j] + "/" + key3[k]
					//本地运行使用以下代码
					//filepath = ".\\data\\" + userName + "\\" + key1[i] + "\\" + key2[j] + "\\" + key3[k]
				} else {
					//服务器上使用以下路径
					filepath = "./data/" + userName + "/" + key1[i] + "/" + key2[j]
					//本地运行使用以下代码
					//filepath = ".\\data\\" + userName + "\\" + key1[i] + "\\" + key2[j]
				}

				err = os.MkdirAll(filepath, os.ModePerm)
				if err != nil {
					config.GetLogger().Warnw("文件夹创建失败",
						"err", err,
					)
					return
				}
			}
		}
	}

	return
}
